<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>{{ $booksreviews->title }} (书评：{{$books->book_name}})</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="author" content="夜读书">
    <meta name="description" content="夜读书中文网">
    <meta name="keywords" content="读书,阅读,小说,文学">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="{{ asset('/bootstrap-3.3.5-dist/css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/yds.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/ucenter.css') }}">
    <script src="{{ asset('/scripts/jquery/jquery-1.11.3.min.js') }}"></script>
    <script src="{{ asset('/bootstrap-3.3.5-dist/js/bootstrap.min.js') }}"></script>
</head>
<body>
@include('books.partials.navtop')
@include('books.partials.nav')
<div id="yds_screen">
<div id="yds_content" class="clearfix">
  <div class="review">
   <h1>{{ $booksreviews->title }}</h1>
   <div class="touxiang">
       <a class="aw-user-name" href="{{url('u')}}/{{$users->uid}}">
          @if($users->avatar_file_min!="")
          <img class="pil" src="http://www.yedushu.com/{{ $users->avatar_file_min }}">
          @else
          <img class="pil" src="http://www.yedushu.com/usersface/default/avatar-min.png">
          @endif
       </a>
   </div>
   <div class="mn"><span>来自: <a class="aw-user-name" href="{{url('u')}}/{{$users->uid}}">{{($users->user_name)}}</a></span><span>{{date('Y-m-d H:i',$booksreviews->add_time)}}</span></div> 
   <div class="mn"><span><a class="" href="{{url('info')}}/{{$booksreviews->book_id}}">{{($books->book_name)}}</a>的评论</span><span class="bigstar{{$booksreviews->rating}}0"></span></div> 
   <div class="reviewtext clearfix">{!!$booksreviews->bookreview!!}</div>
    @if(Session::has('name'))
      <div class="">
          <div class="pinglun">
              <a class="aw-user-name" href="{{url('u')}}/{{$uname->uid}}">
              @if($uname->avatar_file_min!="")
              <img src="http://www.yedushu.com/{{ $uname->avatar_file_min }}">
              @else
              <img src="http://www.yedushu.com/usersface/default/avatar-min.png">
              @endif
              </a>
              <span class="uname"><a href="{{url('u')}}/{{$uname->uid}}">{{ $uname->user_name }}</a></span>
          </div>
          <form id="form" role="form">
          <input type="hidden" name="_token" value="{{ csrf_token() }}" />
          <input type="hidden" name="reviewid" id="reviewid" value="{{ $booksreviews->id }}" />
              <div class="form-group">              
                  <textarea name="content" id="content" class="form-control contxt" rows="1"></textarea>
              </div>
              <div class="right">
                  <span id="ms"></span>
                  <button type="button" id="spbutton" class="btn btn-success">发布</button>
              </div>
          </form>  
      </div>
      <div style="clear:both;"></div>
    @else
      <div class="aw-mod aw-replay-box question">
          <p align="center">要发表回复请先<a href="{{asset('uslogin')}}">登录</a>或<a href="{{asset('usreg')}}">注册</a></p>
      </div>
    @endif
      <div class="comment-list">
          @foreach($booksreviewcomments as $booksreviewcomment)
          <div class="comment-item">
              <div class="avatar">
                <a class="aw-user-img aw-border-radius-5" href="{{url('u')}}/{{$booksreviewcomment->users->uid}}">
                @if($booksreviewcomment->users->avatar_file_min!="")
                  <img id="face" src="http://www.yedushu.com/{{ $booksreviewcomment->users->avatar_file_min }}">
                @else
                  <img id="face" src="http://www.yedushu.com/usersface/avatar-min.png">
                @endif
                </a>
              </div>
              <div class="content">
                 <div class="header">
                     <a href="{{url('u')}}/{{$booksreviewcomment->users->uid}}" id="uname">{{ $booksreviewcomment->users->user_name }}</a>
                     <span>{{date('Y-m-d H:i',$booksreviewcomment->add_time)}}</span>
                 </div>
                 <div class="comment-text">{{$booksreviewcomment->content}}</div>
              </div>
          </div>
          @endforeach
      </div>
  </div>  
  <div class="aside">
  <div class="indent">
    <p>本评论版权属于作者{{($users->user_name)}}，并受法律保护。除非评论正文中另有声明，没有作者本人的书面许可任何人不得转载或使用整体或任何部分的内容。</p>
  </div>
  <div class="pl2"><a href="{{url('info')}}/{{$books->book_id}}">{{$books->book_name}}</a></div>
  <div class="rebook">
    <a href="{{url('info')}}/{{$books->book_id}}"><img src="{{url($books->bimg)}}"></img></a>
    <br/>
    @if($books->zuozhe!="") <span class="p1">作者:{{ $books->zuozhe }}</span><br/> @endif
    @if($books->yuanzuoming!="") <span class="p1">原作名:{{ $books->yuanzuoming }}</span><br/> @endif
    @if($books->isbn!="") <span class="p1">isbn:{{ $books->isbn }}</span><br/> @endif
    @if($books->book_name!="") <span class="p1">书名:{{ $books->book_name }}</span><br/> @endif
    @if($books->yeshu!="") <span class="p1">页数:{{ $books->yeshu }}</span><br/> @endif
    @if($books->yizhe!="") <span class="p1">译者:{{ $books->yizhe }}</span><br/> @endif
    @if($books->dingjia!="") <span class="p1">定价:{{ $books->dingjia }}</span><br/> @endif
    @if($books->chubanshe!="") <span class="p1">出版社:{{ $books->chubanshe }}</span><br/> @endif
    @if($books->zhuangzhen!="") <span class="p1">装帧:{{ $books->zhuangzhen }}</span><br/> @endif
    @if($books->chubannian!="") <span class="p1">出版年:{{ $books->chubannian }}</span><br/> @endif
  </div>
  </div>
</div>
</div>
@include('books.partials.footer')
<script>
$(document).ready(function(){
    $("#spbutton").click(function(){
        if($(".contxt").val().trim() == "" || $(".contxt").val().length < 5)
        {
            $("#ms").html("<span id='msok'><font color='red'>评论内容不能少于5个文字,请认真评论。</font></span>");
            $("#msok").fadeOut(6000);
            $(".contxt").focus();
        }
        else if($(".contxt").val().length > 150)
        {
            $("#ms").html("<span id='msok'><font color='red'>评论内容不能多于150个文字,请认真评论。</font></span>");
            $("#msok").fadeOut(6000);
            $(".contxt").focus();
        }
        else
        {
            //form.submit();
            savepl();
        }
    });
});

function savepl(){
  $.ajax({
    url:'/reviewcomments',
    type:'post', 
    async:true,    //或false,是否异步
    data:{
        'reviewid': $("#reviewid").val(),
        'content': $("#content").val().trim(),
        '_token': '{{csrf_token()}}'
    },
    dataType:'html',
    beforeSend:function(xhr){
        //alert('发送前');
    },
    success:function(data,textStatus,jqXHR){
      if(data=='saveok'){
        //alert('保存成功');
        var html = '<div class="comment-item">'
                 + '<div class="avatar">'
                 + '<a class="aw-user-img aw-border-radius-5" href="'+ $("#uname").attr('href') +'">'
                 + '<img src="'+ $("#face").attr("src") +'">'
                 + '</a>'
                 + '</div>'
                 + '<div class="content">'
                 + '<div class="header"><a href="'+ $("#uname").attr('href') +'">'+ $("#uname").text() +'</a> <span>'+ getdate() +'</span></div>'
                 + '<div class="comment-text">'+ $("#content").val().trim() +'</div>'
                 + '</div>'
                 + '</div>';
        //插入评论
        $(".comment-list").prepend(html); 
        //清空输入的评论框里的内容
        $("#content").val("");
      }else{
        location.href = '/uslogin';
      }
    },
    error:function(xhr,textStatus){
        //alert(textStatus);
    },
    complete:function(){
        //alert('结束');
    }
  });
}
function getdate(){
    //当前时间
    var mydate = new Date(); 
    var year = mydate.getFullYear();
    var month = mydate.getMonth()+1;
    var day = mydate.getDate();
    var hour = mydate.getHours();
    var minute = mydate.getMinutes();
    //var second = mydate.getSeconds();
    var nowtime = year + '-' + p(month) + '-' + p(day) + ' '+ p(hour) + ':' + p(minute);
    return nowtime;
}
function p(s) {
    return s < 10 ? '0' + s:s;
}
</script>
</body>
</html>
